<?php
class ManageBanner extends MX_Controller {
	function __construct(){
		parent::__construct();
		$this->load->model('managebanner_model');
	}
	
	function show(){
		if(modules::run('login/is_admin_logged_in') == false ){
			redirect('login');
			return;
		}
		$vars= array();
		$content = $this->load->view('managebanner_view',$vars,true);
		Template::display($content);
	}
	
	function searchBanner(){		
		if(modules::run('login/is_admin_logged_in') == false ){
			redirect('login');
			return;
		}
		
		$currentPage = $this->input->post('page');
		$page = empty($currentPage) ? 1 : $currentPage;
		
		$itemsPerPage = $this->public_model->getSystemParameterValue("itemsPerPage");
		$numberPageDisplay =  $this->public_model->getSystemParameterValue("numberPageDisplay");
		
		$keywords['search_name'] = $this->input->post('search_name');
		$keywords['search_status'] = $this->input->post('search_status');
		$keywords['limit'] = $itemsPerPage;
		$keywords['offset'] = ($page - 1) *$itemsPerPage;
		$total = $this->input->post('total');
		if(empty($total) || $page == 1){
			$total = $this->managebanner_model->searchTotalBanners($keywords);
		}
	
		$pPaging = $this->commonutils->paging($page, $itemsPerPage, $total, $numberPageDisplay);
		
		$bannerList = $this->managebanner_model->searchBanner($keywords);
		$vars["bannerList"] = $bannerList;
		$vars["pPaging"] = $pPaging;
		
		echo json_encode($vars);
	}
	
}
?>